// pages/component/pickerTime/pickerTime.js
import { formatTime } from '../../../utils/util';
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    startTime: new Date(2022,8,1).getTime(),
    endTime: new Date().getTime(),
    minDate: new Date(2022,8,1).getTime(),
    maxDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      if (type === 'day') {
        return `${value}日`;
      }
      return value;
    },
    showStartTime: false,
    showEndTime: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showPickTime(){
      this.setData({
        showStartTime: true,
      })
    },
    subStartTime(event) {
      console.log(event.detail)
      this.setData({
        startTime: event.detail,
        showStartTime: false,
        showEndTime: true,
      });
    },
    subEndTime(event){
      let _this = this;
      _this.setData({
        endTime: event.detail,
        showEndTime: false,
      });
      var date = new Date(event.detail);
      _this.triggerEvent('pickdateevent', {'startTime': formatTime(new Date(_this.data.startTime)).substring(0,10),'endTime': formatTime(date).substring(0,10)},)
    },
    closePickTime(){
      console.log('1111')
      this.setData({
        showStartTime: false,
      })
    },
    closePickEndTime(){
      this.setData({
        showEndTime: false,
        showStartTime: true,
      })
    }
  }
})
